import * as actionTypes from "./actionTypes";
import { fromJS } from "immutable"; //把数据转为immutable对象，使用这个使用更要使用gget方法，使用set方法去变更state内容
const defaultState = fromJS({
  addressList: [],
});
// 导出一个纯函数
export default (state = defaultState, action) => {
  let data= state.get('addressList').toJS() ;
  switch (action.type) {
    case actionTypes.getAddressList:
      return state.merge({ addressList: fromJS(action.result) })
    case actionTypes.addAdressList:
      data.push(action.result)
      return state.set("addressList", fromJS(data))
      case actionTypes.editAdressList:
       data= data.map(i=>{
        console.log('edit',i.id,action.result)
          if (String(i.id)===String(action.result.id)) {
            console.log('edit')
            i={...action.result}
          } 
          return i;
        })
        return state.set("addressList", fromJS(data))
    default:
      return state;
  }
};
